package cn.jwcat.service.impl;

import cn.jwcat.dealEntity.DealHealth;
import cn.jwcat.dealEntity.HealthDto;
import cn.jwcat.entity.Health;
import cn.jwcat.entity.Staff;
import cn.jwcat.mapper.HealthMapper;
import cn.jwcat.service.IHealthService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 健康状态 服务实现类
 */
@Transactional
@Service
public class HealthServiceImpl extends ServiceImpl<HealthMapper, Health> implements IHealthService {

	@Override
	public List<HealthDto> getHealthInfoByStatus() {
		MPJLambdaWrapper<Health> wrapper = new MPJLambdaWrapper<Health>()
			.selectAll(Health.class)
			.select(Staff::getUsername, Staff::getTelephone)
			.leftJoin(Staff.class, Staff::getStaffId, Health::getStaffId)
			.eq(Staff::getStatus, true)
			.orderByDesc(Health::getCreateTime);
		return this.getBaseMapper().selectJoinList(HealthDto.class, wrapper);
	}

	@Override
	public List<HealthDto> postQuery(DealHealth dealHealth) {
		System.out.println(dealHealth);
		String username = dealHealth.getUsername();
		List<String> time = dealHealth.getTime();
		MPJLambdaWrapper<Health> wrapper = new MPJLambdaWrapper<Health>()
			.selectAll(Health.class)
			.select(Staff::getUsername, Staff::getTelephone)
			.leftJoin(Staff.class, Staff::getStaffId, Health::getStaffId)
			.eq(Staff::getStatus, true)
			.orderByDesc(Health::getCreateTime);
		if (username != null) wrapper.like(Staff::getUsername, username);
		if (time != null) {
			System.out.println(time.get(0));
			System.out.println(time.get(1));
			wrapper.ge(Health::getCreateTime, time.get(0))
				.le(Health::getCreateTime, time.get(1));
		}
		return this.getBaseMapper().selectJoinList(HealthDto.class, wrapper);
	}
}
